package zhihuilan.controlle.wechatMini;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import zhihuilan.common.WxMiniResponse;
import zhihuilan.common.enums.ResultEnum;
import zhihuilan.common.utils.ToolsUtils;
import zhihuilan.config.StaticFiledConfig;
import zhihuilan.config.WxMiniConfig;
import zhihuilan.controlle.BasicController;
import zhihuilan.entity.MyContentInfo;
import zhihuilan.entity.MyStaff;
import zhihuilan.entity.MyUser;
import zhihuilan.entity.tools.WxSessionResult;
import zhihuilan.params.StaticParam;
import zhihuilan.params.query.RegisterQueryParam;
import zhihuilan.service.MyContentInfoService;
import zhihuilan.service.MyMemberService;
import zhihuilan.service.MyStaffService;
import zhihuilan.service.MyUserService;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;

/**
 * 小程序端API </p>
 * 接口说明：</p>
 *
 * @Module 系统基础用户接口模块
 * @Author chenk
 * @Version 1.0.1 (2025-02-24)
 */
@Slf4j
@RestController
@RequestMapping("/app/Content")
public class MyContentInfoController extends BasicController {
    @Resource
    private MyContentInfoService myContentInfoService;

    /**
     * getInfo_获取工厂或市场入驻协议
     *
     * @param param 通用参数查询类【StaticParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getInfo")
    public WxMiniResponse getInfo(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "协议标识不能为空！");
        }
        MyContentInfo result = this.myContentInfoService.selectById(param.getId());
        result.setContent(StringEscapeUtils.unescapeHtml4(result.getContent()));
        return WxMiniResponse.ok(result);
    }

}
